/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

/**
 *
 * @author Lorenzo
 */
@Entity
@NamedQueries({
@NamedQuery(name="comune.trovaDaProvincia", query="SELECT c FROM Comune c WHERE c.provincia=?1"),
@NamedQuery(name="comune.comuneDiUnaProvincia",query="SELECT c FROM Comune c WHERE  c.id=?1 AND c.provincia.id=?2")
})
public class Comune implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column(nullable = false)
    private Integer cap;
    @Column(nullable = false)
    private String nome;
    @ManyToOne
    private Provincia provincia;
    @OneToMany(mappedBy = "comune")
    private List<Cliente> clienti;
    @OneToMany(mappedBy = "comune")
    private List<Negozio> negozi;

    /**
     * Get the value of negozi
     *
     * @return the value of negozi
     */
    public List<Negozio> getNegozi() {
        return negozi;
    }

    /**
     * Set the value of negozi
     *
     * @param negozi new value of negozi
     */
    public void setNegozi(List<Negozio> negozi) {
        this.negozi = negozi;
    }

    public List<Cliente> getClienti() {
        return clienti;
    }

    public void setClienti(List<Cliente> clienti) {
        this.clienti = clienti;
    }

    public Provincia getProvincia() {
        return provincia;
    }

    public void setProvincia(Provincia provincia) {
        this.provincia = provincia;
    }

    /**
     * Get the value of nome
     *
     * @return the value of nome
     */
    public String getNome() {
        return nome;
    }

    /**
     * Set the value of nome
     *
     * @param nome new value of nome
     */
    public void setNome(String nome) {
        this.nome = nome;
    }

    /**
     * Get the value of cap
     *
     * @return the value of cap
     */
    public Integer getCap() {
        return cap;
    }

    /**
     * Set the value of cap
     *
     * @param cap new value of cap
     */
    public void setCap(Integer cap) {
        this.cap = cap;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Comune)) {
            return false;
        }
        Comune other = (Comune) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return id+","+nome + "," + cap;
    }
}
